package com.edu.order.controller;


import com.edu.order.bean.Order;
import com.edu.order.properties.OrderProperties;
import com.edu.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
//@RefreshScope
public class OrderController {
//    @Value("${order.timeout}")
//    private String orderTimeout;
//    @Value("${order.auto-confirm}")
//    private String orderAutoConfirm;

    @Autowired
    private OrderService orderService;

    @Autowired
    private OrderProperties orderProperties;

    @RequestMapping("/order/create")
    public Order createOrder(@RequestBody(required = false) Order order) {
        log.info("createOrder: {}", order != null ? order.toString() : "null");
        return orderService.createOrder(order);
    }

    @RequestMapping("/order/config")
    public String getOrderConfig() {
        return "order.timeout: " + orderProperties.getTimeout() + ";\norder.auto-confirm: " + orderProperties.getAutoConfirm();
    }
}
